<?php

namespace app\common\model;

use think\Db;
use think\Model;

/**
 * 用户
 * @author lcx
 * @date 2019-03-18
 */
class CustomerModel extends Model {

	// 表名
	protected $name = 'customer';

	// 列表查询
	public function getAll($where, $join, $page, $pageSize, $field, $order = 'a.user_id asc', $where2 = '') {
		if ($pageSize > 0) {
			$result = $this->alias('a')
					->where($where)
					->where($where2)
					->join($join)
					->field($field)
					->page($page, $pageSize)
					->order($order)
					->select();
		} else {
			$result = $this->alias('a')
					->where($where)
					->where($where2)
					->join($join)
					->field($field)
					->order($order)
					->select();
		}

		return $result;
	}

	// 数量查询
	public function getCount($where, $join = []) {
		$result = $this->alias('a')
                ->where($where)
				->join($join)
				->count();
		return $result;
	}

	// 单个查询
	public function getOne($where, $join, $field) {
		$result = $this->alias('ce')->where($where)
				->join($join)
				->field($field)
				->find();
		return $result;
	}

	// 添加操作
	public function add($data) {
		$result = $this->insertGetId($data);
		return $result;
	}

	// 编辑操作
	public function edit($where, $data) {
		$result = $this->where($where)->update($data);
		return $result;
	}
	// 分组查询
	public function getGroupAll($where, $join = [],$field='*',$group='') {
		$result = $this->alias('c')->where($where)
					->join($join)
					->group($group)
					->field($field)
					->select();
		return $result;
	}

}
